package com.huawei.appgallery.forum.message.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.huawei.appgallery.forum.base.https.jgw.JGWTabDetailResponse;
import com.huawei.appgallery.forum.base.ui.JGWTabFragment;
import com.huawei.appgallery.forum.message.activity.MessageHomeActivity;
import com.huawei.appgallery.forum.message.bean.ForumRemindCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.BottomButton;
import com.huawei.appgallery.foundation.ui.framework.widget.NodataWarnLayout;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.util.List;
import o.azb;
import o.bqv;
import o.bqy;
import o.bqz.d;
import o.brd;
import o.bri;
import o.bsl;
import o.bsv;
import o.bvj.c;
import o.bvm;
import o.bvn;
import o.bvo;
import o.bvp;
import o.bvp.a;
import o.bvs;
import o.bvy;
import o.bwr;
import o.cdb;
import o.dky;
import o.dky.j;
import o.ContentManager;
import o.eke;
import o.epr;
import o.epv;
import o.eth;
import o.ActivityUtil;
import o.evx;
import o.fho;
import o.fjo;
import o.fjq;
import o.ll;

@FragmentDefine(alias = "message.home", protocol = IMessageHomeFrgProtocol.class)
public class MessageHomeFragment extends JGWTabFragment implements OnClickListener {
    private bqv ʳ;
    private bvo ʹॱ;
    private final SafeBroadcastReceiver ʻʻ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ MessageHomeFragment ॱ;

        {
            this.ॱ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if ("android.net.conn.CONNECTIVITY_CHANGE".equals(intent.getAction()) && epv.ᐝ(this.ॱ.ﹳॱ)) {
                ConnectivityManager connectivityManager = (ConnectivityManager) ContentManager.getInstant().getContext().getSystemService("connectivity");
                NetworkInfo activeNetworkInfo;
                if (connectivityManager != null) {
                    activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
                } else {
                    activeNetworkInfo = null;
                }
                if (this.ॱ.ߴ.getVisibility() == 0 && r0 != null && r0.isConnected()) {
                    this.ॱ.ʿˋ();
                }
            }
        }
    };
    protected bvp ʻˊ;
    private View ʻˋ;
    protected RecyclerView ʼˋ;
    private FrameLayout ꜝ;
    private int ꜞॱ;
    private BottomButton ꜟॱ;
    private RelativeLayout ꞌॱ;
    private Context ﹳॱ;
    private int ﹶ;
    private List<ForumRemindCardBean> ﹺ;
    public BottomButton ﾞ;
    private String ﾞॱ;
    private String ﾟॱ;

    public void ˏ(Bundle bundle) {
        if (bundle == null) {
            ॱˌ();
        } else {
            this.ꜞॱ = bundle.getInt("key_source_type");
            this.ﾞॱ = bundle.getString("key_message_uri");
            this.ﾟॱ = bundle.getString("key_message_domain_id");
            this.ʳ = bsv.ॱ(this.ﾟॱ);
            this.ﹶ = bundle.getInt("key_message_kind_id");
        }
        this.ʼ = new bsl(this, null, this.ﾞॱ, this.ʳ);
        super.ˏ(bundle);
    }

    private void ॱˌ() {
        IMessageHomeFrgProtocol iMessageHomeFrgProtocol = (IMessageHomeFrgProtocol) this.ﹳ.ॱ();
        this.ꜞॱ = iMessageHomeFrgProtocol.getSourceType();
        this.ﾟॱ = iMessageHomeFrgProtocol.getDomainId();
        this.ﾞॱ = iMessageHomeFrgProtocol.getUri();
        this.ʳ = bsv.ॱ(this.ﾟॱ);
        this.ﹶ = iMessageHomeFrgProtocol.getKindId();
    }

    public void ˋ(@NonNull Bundle bundle) {
        bundle.putInt("key_source_type", this.ꜞॱ);
        bundle.putString("key_message_uri", this.ﾞॱ);
        bundle.putString("key_message_domain_id", this.ﾟॱ);
        bundle.putInt("key_message_kind_id", this.ﹶ);
        super.ˋ(bundle);
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        super.ˋ(layoutInflater, viewGroup, bundle);
        this.ﹳॱ = ॱˋ();
        this.ʻˋ = layoutInflater.inflate(e.ʻॱ, viewGroup, false);
        this.ꞌॱ = (RelativeLayout) this.ʻˋ.findViewById(b.ᐝˊ);
        this.ꜝ = (FrameLayout) this.ʻˋ.findViewById(b.ॱʻ);
        this.ꜟॱ = (BottomButton) this.ʻˋ.findViewById(b.ꜟ);
        this.ꜟॱ.setOnClickListener(this);
        ˊ(this.ꜟॱ);
        this.ߴ = (NodataWarnLayout) this.ʻˋ.findViewById(b.ʼˋ);
        this.ߴ.setOnClickListener(this);
        ॱ(this.ߴ);
        ॱـ();
        ॱʾ();
        ˎ(Boolean.valueOf(true));
        return this.ʻˋ;
    }

    public void ᐝ() {
        Z_();
        ((eke) cdb.ॱ(eke.class)).ˋ();
        super.ᐝ();
    }

    protected void ॱʾ() {
        ActivityUtil.registerReceiver(this.ﹳॱ, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"), this.ʻʻ);
    }

    protected void Z_() {
        if (ॱˊ() != null) {
            ll.ˏ(ॱˊ()).ˋ(this.ʻʻ);
        }
        ActivityUtil.unregisterReceiver(this.ﹳॱ, this.ʻʻ);
    }

    private void ॱـ() {
        ॱˉ();
        this.ﾞ = (BottomButton) this.ʻˋ.findViewById(b.ꓸ);
        this.ﾞ.setEnabled(false);
        this.ﾞ.setOnClickListener(new evx(this) {
            final /* synthetic */ MessageHomeFragment ˋ;

            {
                this.ˋ = r1;
            }

            public void ˋ(View view) {
                ((bvn) fho.ˏ().ˋ("Message").ॱ(bvn.class)).ˋ(view.getContext(), this.ˋ.ʳ).ˏ(new fjq<Boolean>(this) {
                    final /* synthetic */ AnonymousClass2 ˎ;

                    {
                        this.ˎ = r1;
                    }

                    public void onComplete(fjo<Boolean> o_fjo_java_lang_Boolean) {
                        if (o_fjo_java_lang_Boolean.ˊ() && ((Boolean) o_fjo_java_lang_Boolean.ॱ()).booleanValue()) {
                            this.ˎ.ˋ.ʿᐝ();
                        }
                    }
                });
            }
        });
        ˊ(this.ﾞ);
        if (this.ꜞॱ == 0) {
            this.ﾞ.setVisibility(8);
            ((eke) cdb.ॱ(eke.class)).ˎ((Activity) this.ﹳॱ, false);
        } else if (this.ꜞॱ == 1 || this.ꜞॱ == 2) {
            this.ﾞ.setVisibility(0);
            if (this.ﹺ != null && this.ﹺ.size() > 0) {
                this.ʻˊ.ˋ(this.ﹺ);
                ˇ();
            }
        }
    }

    private void ˊ(View view) {
        if (epr.ˎ().ॱॱ()) {
            int ॱ;
            LayoutParams layoutParams = view.getLayoutParams();
            if (azb.ˎ(view.getContext())) {
                ॱ = azb.ॱ(ContentManager.getInstant().getContext()) / 3;
            } else {
                ॱ = azb.ॱ(ContentManager.getInstant().getContext()) / 2;
            }
            layoutParams.width = ॱ;
        }
    }

    private void ॱˉ() {
        this.ʼˋ = (RecyclerView) this.ʻˋ.findViewById(b.ˋ);
        this.ʼˋ.setHasFixedSize(true);
        this.ʼˋ.setNestedScrollingEnabled(false);
        this.ʼˋ.setLayoutManager(new LinearLayoutManager(this.ʻˋ.getContext(), 1, false));
        this.ʻˊ = new bvp(this.ﹳॱ, this.ﾟॱ);
        this.ʼˋ.setAdapter(this.ʻˊ);
        this.ʻˊ.ॱ(new a(this) {
            final /* synthetic */ MessageHomeFragment ˋ;

            {
                this.ˋ = r1;
            }

            public void ˎ(long j, String str) {
                if (this.ˋ.ꜞॱ == 1 || this.ˋ.ꜞॱ == 2) {
                    this.ˋ.ॱˑ();
                    this.ˋ.ˈˊ();
                }
            }
        });
    }

    public boolean ˊ(TaskFragment taskFragment, TaskFragment.b bVar) {
        boolean ˊ = super.ˊ(taskFragment, bVar);
        if (bVar.ˋ.getResponseCode() == 0 && bVar.ˋ.getRtnCode_() == 0 && (bVar.ˋ instanceof JGWTabDetailResponse)) {
            if (new bvy().ˏ(this.ﹶ, this.ꜞॱ)) {
                ˊ((JGWTabDetailResponse) bVar.ˋ);
                return ˊ;
            }
            ˎ((JGWTabDetailResponse) bVar.ˋ);
        }
        return ˊ;
    }

    private void ˊ(final JGWTabDetailResponse jGWTabDetailResponse) {
        new bvs().ˎ(this.ﾟॱ).ˏ(new fjq<bvo>(this) {
            final /* synthetic */ MessageHomeFragment ˊ;

            public void onComplete(fjo<bvo> o_fjo_o_bvo) {
                if (o_fjo_o_bvo.ˊ()) {
                    bvo o_bvo = (bvo) o_fjo_o_bvo.ॱ();
                    if (o_bvo == null) {
                        this.ˊ.ͺ(1);
                        return;
                    }
                    List<LayoutData> ᐝॱ = jGWTabDetailResponse.ᐝॱ();
                    if (ᐝॱ != null && ᐝॱ.size() > 0) {
                        for (LayoutData layoutData : ᐝॱ) {
                            if ("forumremindcardv4".equals(layoutData.ˏ()) && layoutData.ˋ().size() != 0) {
                                this.ˊ.ॱ(o_bvo, layoutData.ˋ());
                                break;
                            }
                        }
                    }
                    this.ˊ.ˎ(jGWTabDetailResponse);
                    this.ˊ.ˈˊ();
                }
            }
        });
    }

    private void ˎ(JGWTabDetailResponse jGWTabDetailResponse) {
        ˎ(Boolean.valueOf(false));
        if (this.ꜞॱ == 2 || this.ꜞॱ == 0) {
            brd.ॱ.ˊ(bqy.ˋ().ˎ(this.ﹳॱ), this.ﾟॱ);
        }
        ॱ(jGWTabDetailResponse);
    }

    public void ˏ(bri o_bri, BaseDetailResponse baseDetailResponse) {
        super.ˏ(o_bri, baseDetailResponse);
        if ((baseDetailResponse instanceof JGWTabDetailResponse) && !((JGWTabDetailResponse) baseDetailResponse).ˏ()) {
            ͺ(ˎ((ResponseBean) baseDetailResponse));
        }
    }

    public void ॱ(NodataWarnLayout nodataWarnLayout) {
        if (nodataWarnLayout != null) {
            nodataWarnLayout.setWarnImage(dky.a.ˊˊ);
            nodataWarnLayout.setWarnTextOne(j.ᐝᐝ);
            nodataWarnLayout.setViewVisible(NodataWarnLayout.e.WARN_BTN, 8);
            nodataWarnLayout.setViewVisible(NodataWarnLayout.e.WARN_TEXTTWO, 8);
        }
    }

    public void ͺ(int i) {
        this.ꞌॱ.setVisibility(8);
        this.ꜝ.setVisibility(8);
        this.ߴ.setVisibility(0);
        if (i == 3) {
            this.ߴ.setWarnImage(c.ॱˎ);
            this.ߴ.setWarnTextOne(d.ˋᐝ);
            this.ꜟॱ.setVisibility(0);
            return;
        }
        this.ߴ.setWarnImage(c.ॱˎ);
        this.ߴ.setWarnTextOne(d.ˎ);
        this.ꜟॱ.setVisibility(8);
    }

    private void ˎ(Boolean bool) {
        if (bool.booleanValue()) {
            this.ꞌॱ.setVisibility(8);
            this.ꜝ.setVisibility(0);
            this.ߴ.setVisibility(8);
            this.ꜟॱ.setVisibility(8);
            return;
        }
        this.ꞌॱ.setVisibility(0);
        this.ꜝ.setVisibility(8);
        this.ߴ.setVisibility(8);
        this.ꜟॱ.setVisibility(8);
    }

    private void ॱ(JGWTabDetailResponse jGWTabDetailResponse) {
        List<LayoutData> ᐝॱ = jGWTabDetailResponse.ᐝॱ();
        if (ᐝॱ == null || ᐝॱ.size() <= 0) {
            ͺ(4);
            return;
        }
        for (LayoutData layoutData : ᐝॱ) {
            if ("forumremindcardv4".equals(layoutData.ˏ()) && layoutData.ˋ().size() != 0) {
                ˎ(layoutData.ˋ());
                return;
            }
        }
    }

    private void ˎ(List list) {
        this.ﹺ = list;
        if (this.ﹺ != null && this.ﹺ.size() > 0) {
            this.ʻˊ.ˋ(this.ﹺ);
            ˇ();
        }
    }

    private void ॱˑ() {
        if (bwr.ˊ.ˊ() > 0) {
            this.ﾞ.setEnabled(true);
        } else {
            this.ﾞ.setEnabled(false);
        }
    }

    private void ˇ() {
        if (this.ﹺ != null && this.ﹺ.size() > 0) {
            int i = 0;
            for (int i2 = 0; i2 < this.ﹺ.size(); i2++) {
                ForumRemindCardBean forumRemindCardBean = (ForumRemindCardBean) this.ﹺ.get(i2);
                if (forumRemindCardBean.ᐝ() > 0) {
                    i += forumRemindCardBean.ᐝ();
                }
            }
            bwr.ˊ.ˎ((long) i);
        }
        ॱˑ();
    }

    private void ʿᐝ() {
        if (this.ﹺ != null && this.ﹺ.size() > 0) {
            int i = 0;
            for (int i2 = 0; i2 < this.ﹺ.size(); i2++) {
                ForumRemindCardBean forumRemindCardBean = (ForumRemindCardBean) this.ﹺ.get(i2);
                if (forumRemindCardBean.ᐝ() > 0) {
                    i += forumRemindCardBean.ᐝ();
                }
                forumRemindCardBean.ˎ(0);
            }
            this.ʻˊ.ˋ(this.ﹺ);
            bwr.ˊ.ॱ((long) i);
            ˈˊ();
        }
        ॱˑ();
    }

    public void onClick(View view) {
        if (b.ꜟ == view.getId()) {
            eth.ˊ(this.ﹳॱ);
        } else if (b.ʼˋ == view.getId()) {
            ʿˋ();
        }
    }

    private void ʿˋ() {
        ˎ(Boolean.valueOf(true));
        ʿˊ();
    }

    public void ˋ(bvo o_bvo) {
        if (ॱ(o_bvo, this.ﹺ) && this.ʻˊ != null) {
            this.ʻˊ.ˊ();
        }
        ˈˊ();
    }

    private boolean ॱ(bvo o_bvo, List list) {
        if (list == null || list.size() == 0 || o_bvo == null) {
            return false;
        }
        this.ʹॱ = o_bvo;
        for (Object next : list) {
            if (next instanceof ForumRemindCardBean) {
                ForumRemindCardBean forumRemindCardBean = (ForumRemindCardBean) next;
                switch (forumRemindCardBean.ॱˊ()) {
                    case 1:
                        forumRemindCardBean.ˊ(o_bvo.ˎ());
                        break;
                    case 2:
                        forumRemindCardBean.ˊ(o_bvo.ˏ());
                        break;
                    case 3:
                        forumRemindCardBean.ˊ(o_bvo.ˊ());
                        break;
                    case 4:
                        forumRemindCardBean.ˊ(o_bvo.ॱ());
                        break;
                    case 5:
                        forumRemindCardBean.ˊ(o_bvo.ˋ());
                        break;
                    case 6:
                        forumRemindCardBean.ˊ(o_bvo.ᐝ());
                        break;
                    case 7:
                        forumRemindCardBean.ˊ(o_bvo.ʼ());
                        break;
                    default:
                        break;
                }
            }
        }
        return true;
    }

    private void ˈˊ() {
        if (new bvy().ˏ(this.ﹶ, this.ꜞॱ) && this.ʹॱ != null && this.ﹺ != null && this.ﹺ.size() != 0) {
            Activity ॱˋ = ॱˋ();
            if (ॱˋ instanceof MessageHomeActivity) {
                Intent intent = new Intent();
                intent.putExtra("result_success", true);
                bvm ˈᐝ = ˈᐝ();
                intent.putExtra("replyMsgCnt", ˈᐝ.ˊ());
                intent.putExtra("importantMsgCnt", ˈᐝ.ˋ());
                intent.putExtra("followMsgCnt", ˈᐝ.ॱ());
                intent.putExtra("growthMsgCnt", ˈᐝ.ˏ());
                intent.putExtra("likeMsgCnt", ˈᐝ.ˎ());
                intent.putExtra("pushMsgCnt", ˈᐝ.ʽ());
                intent.putExtra("reviewMsgCnt", ˈᐝ.ॱॱ());
                intent.putExtra("replyMsgSwitch", this.ʹॱ.ˎ());
                intent.putExtra("importantMsgSwitch", this.ʹॱ.ˊ());
                intent.putExtra("followMsgSwitch", this.ʹॱ.ˋ());
                intent.putExtra("growthMsgSwitch", this.ʹॱ.ॱ());
                intent.putExtra("likeMsgSwitch", this.ʹॱ.ˏ());
                intent.putExtra("pushMsgSwitch", this.ʹॱ.ᐝ());
                intent.putExtra("reviewMsgSwitch", this.ʹॱ.ʼ());
                ॱˋ.setResult(-1, intent);
            }
        }
    }

    private bvm ˈᐝ() {
        bvm o_bvm = new bvm();
        for (Object next : this.ﹺ) {
            if (next instanceof ForumRemindCardBean) {
                ForumRemindCardBean forumRemindCardBean = (ForumRemindCardBean) next;
                switch (forumRemindCardBean.ॱˊ()) {
                    case 1:
                        o_bvm.ˊ(forumRemindCardBean.ᐝ());
                        break;
                    case 2:
                        o_bvm.ॱ(forumRemindCardBean.ᐝ());
                        break;
                    case 3:
                        o_bvm.ˎ(forumRemindCardBean.ᐝ());
                        break;
                    case 4:
                        o_bvm.ˏ(forumRemindCardBean.ᐝ());
                        break;
                    case 5:
                        o_bvm.ˋ(forumRemindCardBean.ᐝ());
                        break;
                    case 6:
                        o_bvm.ʼ(forumRemindCardBean.ᐝ());
                        break;
                    case 7:
                        o_bvm.ॱॱ(forumRemindCardBean.ᐝ());
                        break;
                    default:
                        break;
                }
            }
        }
        return o_bvm;
    }
}
